<?php

!defined('IN_SYSTEM') && exit('Access denied');

class authControlPage extends commonControlPage{

    public function indexModule() {
    }

    public function signinModule() {
        if ($this->user) {
            header("Location: system.php");
            exit;
        }
        if (POST && $this->submitcheck()) {
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            $verify = $_POST['verify'];

            // 验证码
            if ($this->verifyCheck($verify)) {
                csetcookie($verify_cookie_name,null,-1);
                $user = $_ENV['db']->fetch("SELECT * FROM admincp_member WHERE `username` = '{$username}'");
                if ($user['password'] == $password) {
                    $auth = cauthcode(json_encode($user),'ENCODE');
                    csetcookie('auth',$auth);
                    $_ENV['db']->runSql("UPDATE `admincp_member` SET `last_login_time` = '".time()."', `last_login_ip` = '".ip2long($_SERVER['REMOTE_ADDR'])."', `login_sum` = `login_sum` + 1 WHERE `uid` = '{$user['uid']}'");
                    header("Location: ?app=portal&mod=main");
                    exit();
                }
            } else {
                $this->view->message = '-1';
            }
        }
        $this->view->render('admincp/login');
    }

    public function signoutModule() {
        csetcookie('auth',NULL,-1);
        header('location: ?app=auth&mod=signin');
    }
}